# coding=utf-8
import os


class BaseConfig(object):
    PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__))
    SQLALCHEMY_DATABASE_URI = "mysql+pymysql://%s:%s@%s:%d/%s?charset=utf8&use_unicode=0" % (
        'root', '123456',
        '172.16.3.192', 3307,
        'beetle-auth'
    )

    # 自动回收连接的秒数。这对 MySQL 是必须的，默认 情况下 MySQL 会自动移除闲置 8 小时或者以上的连接。 需要注意地是如果使用 MySQL 的话， Flask-SQLAlchemy 会自动地设置这个值为 2 小时。
    SQLALCHEMY_POOL_RECYCLE = 1200
    # 控制在连接池达到最大值后可以创建的连接数。当这些额外的 连接回收到连接池后将会被断开和抛弃。
    SQLALCHEMY_MAX_OVERFLOW = 10

    DEBUG = False

    ENABLED_MODULES = (
        'user',
        'login',
        'menu',
        'role',
        # 'notify',
        'common',
        'api',
    )

    AUTHORIZATIONS = {
        'oauth2_password': {
            'type': 'oauth2',
            'flow': 'password',
            'scopes': {},
            'tokenUrl': '/auth/oauth2/token',
        },
    }

    JOBS = [
        {
            'id': 'logoutJob',
            'func': 'app.modules.common.scheduler:logoutJob',
            'args': (),
            'trigger': 'interval',
            'minutes': 30
        }
    ]

    SWAGGER_UI_JSONEDITOR = True
    SWAGGER_UI_OAUTH_CLIENT_ID = 'documentation'
    SWAGGER_UI_OAUTH_REALM = 'Authentication for beetle-auth documentation'
    SWAGGER_UI_OAUTH_APP_NAME = 'beetle-auth documentation'

    SQLALCHEMY_TRACK_MODIFICATIONS = True
    CSRF_ENABLED = True

    ROLE_ADMIN_ID = 1


class DevelopmentConfig(BaseConfig):
    DEBUG = False


class TestingConfig(BaseConfig):
    DEBUG = True


class ProductionConfig(BaseConfig):
    pass


class LocalConfig(BaseConfig):
    DEBUG = True


class AuthConfig(object):
    pass


class ZenTaoConfig(object):
    IS_USE_ZENTAO = False

    ZENTAO_GETSESSION_URL = '/index.php?m=api&f=getSessionID&t=json'
    ZENTAO_USER_LOGIN_URL = '/index.php?m=user&f=login&t=json'

    ZENTAO_COMPANY_VIEW_URL = '/index.php?m=company&f=view&t=json'
    ZENTAO_COMPANY_BROWSE_URL = '/index.php?m=company&f=browse&t=json&param=0&type=bydept&orderBy=id&recTotal=9999&recPerPage=9999&pageID=1'
    ZENTAO_COMPANY_GROUP_URL = '/index.php?m=group&f=browse&t=json'

    ZENTAO_PROJECT_LIST_URL = '/index.php?m=project&f=ajaxGetDropMenu&t=json&objectID=0&module=project&method=task&extra=all'
    ZENTAO_PROJECT_TEAM_URL = '/index.php?m=project&f=team&t=json'
    ZENTAO_PROJECT_VIEW_URL = '/index.php?m=project&f=view&t=json'
